<template>
    <div class="layout-container confidence-evaluate">
      <BaseInfoForm :sampleId="route.query.sampleId"/>
      <TagIcon :title="`${route.query.nodeId}计算结果`" :style="tagIconStyle" />
      <div class="layout-container-table">
        <CommonTable
          :data="state.tableData"
          v-model:page="page"
          :total="total"
          v-loading="loading"
          :showPagination="false"
          :showSelection="false"
          :showIndex="false"
          @span-method="objectSpanMethod"
          @onQuery="onQuery"
        >
          <el-table-column prop="evaluateMetric" label="性能偏差评估指标" />
          <el-table-column prop="performanceResult" label="推算结果" />
          <el-table-column prop="unit" label="单位" />
        </CommonTable>
      </div>
  
      <div class="step-buttons common-buttons">
        <el-button type="primary" @click="onBack">返回</el-button>
      </div>
    </div>
  </template>
  
  <script lang="ts" setup>
  import { onMounted, reactive, ref } from 'vue';
  import { ElMessage, ElMessageBox } from 'element-plus';
  import { useRoute, useRouter } from 'vue-router';
  import CommonTable from '@/components/common-table/index.vue';
  import TagIcon from '@/components/tag-icon/index.vue';
  import { Page } from '@/components/common-table/type';
  import BaseInfoForm from '../../BaseInfoForm/index.vue';
  import {
    httpConfidenceEvaluateList,
    httpStartEvaluate,
    httpDeviationFuseComputing,
    httpDeviationComputingResult,
  } from '@/api/antiJamPerformCalculateSystem';
  import { downloadFile } from '@/utils/tools';
  import LineChart from '../LineEchart/index.vue';
  import FlowStep from '../../FlowStep/index.vue'
  
  let $router = useRouter();
  const route = useRoute();
  
  const tagIconStyle = reactive({ padding: '16px' });
  const state = reactive<any>({
    tableData: [],
  });
  const loading = ref<boolean>(false);
  const page = reactive<Page>({
    current: 1,
    pageSize: 20,
  });
  const total = ref<number>(0);
  
  onMounted(() => {
    onQuery({ pageNo: 1 });
  });
  
  // 查询数据
  const onQuery = (val: any) => {
    loading.value = true;
    if (route.query.nodeId === '导引头参数不同的性能偏差') {
      const params = {
        pageSize: page.pageSize,
        pageNo: page.current,
        sampleId: route.query.sampleId,
        hisSampleId: route.query.hisSampleId,
        type: "1",
        ...val,
      };
      httpDeviationComputingResult(params).then((res) => {
        const result = res.data;
        loading.value = false;
        if (result) {
          const metricNameMap: { [key: string]: string } = {
            "dytName": "导引头型号偏差",
            "runningSpeed": "运动速度偏差",
            "powerUpDistance": "开机距离偏差",
            "dytType": "导引头类型偏差",
            "workingRange": "工作频段偏差",
            "workingFreq": "工作频率偏差",
            "power": "功率偏差",
            "workingBandwidth": "工作带宽偏差",
            "pulseWidth": "脉冲宽度偏差",
            "beamWidth": "波束宽度偏差",
            "ballisticType": "弹道类型偏差",
            "launchKinEnergy": "发射动能偏差",
            "launchSpeed": "发射速度偏差"
          };

          const rows = Object.keys(result).map((key) => {
            const metricName = key;
            return {
              evaluateMetric: metricNameMap[metricName] || metricName,
              performanceResult: result ? result[metricName] : '-',
              unit: '-' // 可以根据需要添加单位
            };
          });
          state.tableData = rows;
        } else {
          state.tableData = [];
        }
      });
    }

    if (route.query.nodeId === '压制类干扰参数不同的性能偏差') {
      const params = {
        pageSize: page.pageSize,
        pageNo: page.current,
        sampleId: route.query.sampleId,
        hisSampleId: route.query.hisSampleId,
        type: "3",
        ...val,
      };
      httpDeviationComputingResult(params).then((res) => {
        const result = res.data;
        loading.value = false;
        if (result) {
          const metricNameMap: { [key: string]: string } = {
            "equipmentModel": "设备型号偏差",
            "equipmentType": "设备类型偏差",
            "equipmentPlatform": "设备平台偏差",
            "effectiveRadiatedPower": "有效辐射功率偏差",
            "disruptionBand": "干扰频段偏差",
            "interBand": "干扰带宽偏差",
            "maxEffectiveRange": "最大有效射程偏差",
            "maxInterTarget": "最大干扰目标数偏差",
            "chaffCloudShape": "干扰弹云形状偏差",
            "chaffCloudSize": "干扰弹云大小偏差",
            "firingRange": "射程偏差",
            "launchType": "发射类型偏差",
            "launcherCount": "发射架数偏差", 
          };

          const rows = Object.keys(result).map((key) => {
            const metricName = key;
            return {
              evaluateMetric: metricNameMap[metricName] || metricName,
              performanceResult: result? result[metricName] : '-',
              unit: '-' // 可以根据需要添加单位
            };
          });

          state.tableData = rows;
        } else {
          state.tableData = [];
        }
      });
    }

    if (route.query.nodeId === '欺骗类干扰参数不同的性能偏差') {
      const params = {
        pageSize: page.pageSize,
        pageNo: page.current,
        sampleId: route.query.sampleId,
        hisSampleId: route.query.hisSampleId,
        type: "2",
        ...val,
      };
      httpDeviationComputingResult(params).then((res) => {
        const result = res.data;
        loading.value = false;
        if (result) {
          const metricNameMap: { [key: string]: string } = {
            "equipmentModel": "设备型号偏差",
            "equipmentType": "设备类型偏差",
            "equipmentPlatform": "设备平台偏差",
            "arrangeMethod": "部署方式偏差",
            "arrangeTime": "部署时间偏差",
            "stayTime": "停留时间偏差",
            "cornerReflectorSize": "角反射器尺寸偏差",
            "equipmentCount": "设备数量偏差"
          };

          const rows = Object.keys(result).map((key) => {
            const metricName = key;
            return {
              evaluateMetric: metricNameMap[metricName] || metricName,
              performanceResult: result ? result[metricName] : '-',
              unit: '-' // 可以根据需要添加单位
            };
          });

          state.tableData = rows;
        } else {
          state.tableData = [];
        }
      });
      
    }

    if (route.query.nodeId === '组合类干扰参数不同的性能偏差') {
      const params = {
        pageSize: page.pageSize,
        pageNo: page.current,
        sampleId: route.query.sampleId,
        hisSampleId: route.query.hisSampleId,
        type: "4",
        ...val,
      };
      httpDeviationComputingResult(params).then((res) => {
        const result = res.data;
        loading.value = false;
        if (result) {
          const metricNameMap: { [key: string]: string } = {
            "equipmentModel": "设备型号偏差",
            "equipmentType": "设备类型偏差",
            "equipmentPlatform": "设备平台偏差",
            "effectiveRadiatedPower": "有效辐射功率偏差",
            "disruptionBand": "干扰频段偏差",
            "interBand": "干扰带宽偏差",
            "maxEffectiveRange": "最大有效射程偏差",
            "maxInterTarget": "最大干扰目标数偏差",
            "chaffCloudShape": "干扰弹云形状偏差",
            "chaffCloudSize": "干扰弹云大小偏差",
            "firingRange": "射程偏差",
            "launchType": "发射类型偏差",
            "launcherCount": "发射架数偏差",
            "similarityResult": "相似性结果",
            "arrangeMethod": "部署方式偏差",
            "arrangeTime": "部署时间偏差",
            "stayTime": "停留时间偏差",
            "cornerReflectorSize": "角反射器尺寸偏差",
            "equipmentCount": "设备数量偏差",
          };

          const rows = Object.keys(result).map((key) => {
            const metricName = key;
            return {
              evaluateMetric: metricNameMap[metricName] || metricName,
              performanceResult: result ? result[metricName] : '-',
              unit: '-' // 可以根据需要添加单位
            };
          });

          state.tableData = rows;
        } else {
          state.tableData = [];
        }
      });
    }

  };
  
  // 合并列
  const objectSpanMethod = (obj: any) => {
    const { row, column, rowIndex, columnIndex } = obj;
  };
  
  // 返回
  const onBack = () => {
    $router.push({
      path: '/antiJamPerformCalculateSystem/computeAtlas',
      query: {
        sampleId: route.query.sampleId,
        hisSampleId: route.query.hisSampleId,
        deviationFuseResult: route.query.deviationFuseResult
      },
    });
  };
  
  </script>
  
  <style lang="scss" scoped>
  @import '@/assets/style/buttons';
  .confidence-evaluate {
    .layout-container-table {
      .el-button--small {
        background: transparent;
        color: rgba(24, 81, 237, 1);
      }
    }
  
    .step-buttons {
      display: flex;
      justify-content: center;
      box-shadow: 0px 0px 10px rgba(218, 222, 224, 1);
      padding: 10px 0;
    }
  }
  .el-button {
      background: rgb(1, 18, 90);
      border: 0;
    }

  </style>